<template>
  <div class="loginContainer">
    <el-card shadow="always">
      <div class="pic"></div>
      <div class="text-item">
        <el-form
          :model="formData"
          status-icon
          :rules="rules"
          ref="ruleForm"
          label-width="100px"
          class="demo-ruleForm"
        >
          <el-form-item>
            <h2>店铺注册</h2>
          </el-form-item>
          <el-form-item label="店铺账号" prop="username">
            <el-input
              type="text"
              v-model="formData.username"
              autocomplete="off"
            ></el-input>
          </el-form-item>
          <el-form-item label="店铺名称" prop="nickName">
            <el-input
              type="text"
              v-model="formData.nickName"
              autocomplete="off"
            ></el-input>
          </el-form-item>
          <el-form-item label="密码" prop="password">
            <el-input
              type="password"
              v-model="formData.password"
              autocomplete="off"
            ></el-input>
          </el-form-item>
          <el-form-item label="确认密码" prop="checkPassword">
            <el-input
              type="password"
              v-model="formData.checkPassword"
              autocomplete="off"
            ></el-input>
          </el-form-item>
          <el-form-item>
            <el-link href="http://chewelve.top:7070/Login" type="primary"
              >已有账号,登录</el-link
            >
          </el-form-item>
          <el-form-item>
            <el-button type="primary" @click="submitForm('ruleForm')"
              >注册</el-button
            >
            <el-button @click="resetForm('ruleForm')">重置</el-button>
          </el-form-item>
        </el-form>
      </div>
    </el-card>
  </div>
</template>

<script>
import {storregister} from "../api/user"
export default {
  data() {
    return {
      formData: {
        username: "",
        password: "",
        checkPassword: "",
        nickName: "",
      },
      rules: {
        // required 选择必填 trigger: 'blur' blur失去焦点
        username: [
          { required: true, message: "请输入用户名", trigger: "blur" },
        ],
        password: [{ required: true, message: "请输入密码", trigger: "blur" }],
        checkPassword: [
          { required: true, message: "请输入密码", trigger: "blur" },
        ],
        nickName: [
          { required: true, message: "请输入店铺名称", trigger: "blur" },
        ],
      },
    };
  },
  methods: {
    submitForm(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          storregister(this.formData)
            .then(({ data }) => {
              if (data.code === 200) {
                window.location.href = "http://chewelve.top:7070/Login";
              } else {
                this.$message({ type: "error", message: data.msg });
              }
            })
            .catch((err) => {
              console.log(err);
            });
        } else {
          console.log("error submit!!");
          return false;
        }
      });
    },
    //重置
    resetForm(formName) {
      this.$refs[formName].resetFields();
    },
  },
};
</script>

<style scoped>
.loginContainer {
  width: 100vw;
  height: 100vh;
  display: flex;
  justify-content: center;
  align-items: center;
}
.el-card {
  width: 900px;
  height: 450px;
}
.pic {
  background: url("../assets/hh.png") no-repeat;
  width: 600px;
  height: 450px;
  position: absolute;
}
.text-item {
  position: relative;
  width: 300px;
  height: 450px;
  margin-left: 500px;
}
.el-link {
  display: inline;
}
.el-form-item__content {
  line-height: 0px;
}
.el-form-item {
 margin-bottom: 15px; 
}
</style>